﻿CREATE PROCEDURE [acms].[PostControl_Put]
	@PostId int,
	@TemplateControlId int,
	@Value Xml,
	@VersionId timestamp,
	@IdOut int output,
	@VersionIdOut timestamp output
AS
	if Exists (Select null FROM PostControls with (nolock) where PostId = @PostId and TemplateControlId = @TemplateControlId) begin
		update PostControls
		set
			Value = @Value
		where PostId = @PostId 
			and TemplateControlId = @TemplateControlId
			and VersionId = @VersionId
		if @@Rowcount = 0
			return -100
 	end
 	else begin
 		insert into PostControls
 			(PostId, TemplateControlId, Value)
 		values
 			(@PostId, @TemplateControlId, @Value)
 	end
 	
 	select @IdOut = Id, @VersionIdOut = VersionId from PostControls with (nolock) where PostId = @PostId and TemplateControlId = @TemplateControlId
	
	
RETURN 0;